<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8"/>
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <title>success</title>
    <style>
        body {
            background-color: #EEEEE0;
        }
    </style>
</head>

<body>

<input name="name" id="name" type = "text">
<input name="password" type="text" id="password">
<button id="btn1">ajax添加用户</button>
</body>
</html>
<script>
    $(function () {

        $("#btn1").on("click", function () {
            var name = $("#name").val();
            var password = $("#password").val();
            if (name == "" || password == "") {
                alert("输入正确信息");
                return;
            }
            //提交表单
            $.ajax({
                url: "/user/Add",
                type: "post",
                dataType: "json",
                data: {
                    name: name,
                    password: password
                },
                success: function (result) {
                    console.log(result);
                    if (result == 200) {
                        window.location.href = "success";
                    } else {
                        alert("失败");
                    }
                }
            })
        })
    })
</script>